package com.example.demo.demos.现场调查;

import java.util.ArrayList;
import java.util.List;

public class FindConsecutiveIndices {
    public static List<List<Integer>> findConsecutiveIndices(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        if (nums == null || nums.length == 0) {
            return result;
        }

        int start = 0;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[i - 1]) {
                if (i - start > 1) {
                    List<Integer> range = new ArrayList<>();
                    range.add(start);
                    range.add(i - 1);
                    result.add(range);
                }
                start = i;
            }
        }

        if (nums.length - start > 1) {
            List<Integer> range = new ArrayList<>();
            range.add(start);
            range.add(nums.length - 1);
            result.add(range);
        }

        return result;
    }

    public static void main(String[] args) {
        int[] nums = {1,1,3,3,4,5,2, 2, 3, 3, 3, 4, 4, 3, 3};
        List<List<Integer>> ranges = findConsecutiveIndices(nums);
        System.out.println(ranges);
    }
}
